package org.akomantoso.core.data;

import java.io.IOException;

import org.akomantoso.core.data.attribute.Link;
import org.akomantoso.core.data.group.ANinline;
import org.akomantoso.core.io.Input;
import org.akomantoso.core.io.Output;
import org.akomantoso.core.io.OutputUtil;
import org.akomantoso.core.visitor.AKVisitor;


/**
 * The element ref is an inline element containing a legal references (i.e. a reference to a document with legal status
 * and for which an Akoma Ntoso URI exists).
 * 
 * <pre>
 * 	<xsd:element name="ref">
 * 		<xsd:complexType mixed="true">
 * 			<xsd:complexContent>
 * 				<xsd:extension base="inlinereq">
 * 					<xsd:attributeGroup ref="link"/>
 * 				</xsd:extension>
 * 			</xsd:complexContent>
 * 		</xsd:complexType>
 * 	</xsd:element>
 * </pre>
 * 
 * @author <a href="mailto:jacques.militello@gmail.com">Jacques Militello</a>
 * 
 * @since http://www.akomantoso.org/1.0
 */
public final class Ref extends InlineReqType implements ANinline, Link {

	public static final String ELEMENT = "ref";

	private String _href;
	
	/**
	 * @see org.akomantoso.core.data.attribute.Link#getHref()
	 */
	@Override
	public String getHref() {
		return _href;
	}

	/**
	 * @see org.akomantoso.core.data.attribute.Link#setHref(java.lang.String)
	 */
	@Override
	public void setHref(String href) {
		_href = href;
	}

	/**
	 * @see org.akomantoso.core.data.InlineReqType#writeExternal(org.akomantoso.core.io.Output)
	 */
	@Override
	public <E extends Output> void writeExternal(E out) throws IOException {
		out.writeStart(ELEMENT);
		OutputUtil.writeMandatoryAttribute(out, Link.ATTRIBUTE, _href, this);
		super.writeExternal(out);
		out.writeEnd();
	}
	
	

	/**
	 * @see org.akomantoso.core.data.InlineReqType#readExternal(org.akomantoso.core.io.Input)
	 */
	@Override
	public <E extends Input> void readExternal(E in) throws IOException {
		_href = in.readAttribute(Link.ATTRIBUTE);
		super.readExternal(in);
	}

	/**
	 * @see org.akomantoso.core.visitor.AKVisitable#accept(org.akomantoso.core.visitor.AKVisitor)
	 */
	@Override
	public void accept(AKVisitor visitor) {
		if (visitor.visitBegin(this)) {
			internalAccept(visitor);
			visitor.visitEnd(this);
		}
	}

}